package models

import (
	"database/sql"
	"gitee.com/yanxinfire/geektime-week2-error/cmd/config"
	"github.com/pkg/errors"
)

type User struct {
	Id   int
	Name string
	Addr string
}

func GetUserById(u *User) (*User, error) {
	ou, err := config.Config.DB.DoQuery(u)
	if err != nil {
		if err == sql.ErrNoRows {
			return nil, errors.New("Can't find specified user!")
		} else {
			return nil, errors.Wrap(err, "Fail to find specified user!")
		}
	}
	return ou.(*User), nil
}
